import 'package:easy_refresh/easy_refresh.dart';
import 'package:get/get.dart';
import 'package:kq_flutter_core_widget/config/kq_core_global.dart';
import 'package:kq_flutter_widgets/config/kq_global.dart';
import 'package:kq_flutter_core_widget/utils/event_bus_utils.dart';

import '../../../config/global.dart';
import '../../../event/theme_change_event.dart';
import 'state.dart';

class HomeController extends GetxController {
  final EasyRefreshController refreshController = EasyRefreshController(
      controlFinishLoad: true, controlFinishRefresh: true);

  final HomeState state = HomeState();

  /// 下拉刷新
  void onRefresh() async {
    // _requestAppSort();
    refreshController.finishRefresh();
  }

  void onLoad() {
    Future.delayed(const Duration(seconds: 3), () {
      // refreshController.finishLoad();
      refreshController.finishLoad(IndicatorResult.noMore);
    },);
  }

  void changeTheme(int position) {
    switch (position) {
      case 0:
        KqCoreGlobal.prefs!.setString('theme', Global.themeYellow).then((value) {
          EventBusUtils.global.fire(ThemeChangeEvent.getInstance());
          update();
        });
        break;
      case 1:
        KqCoreGlobal.prefs!.setString('theme', Global.themeRed).then((value) {
          EventBusUtils.global.fire(ThemeChangeEvent.getInstance());
          update();
        });
        break;
      case 2:
        KqCoreGlobal.prefs!.setString('theme', Global.themeBlue).then((value) {
          EventBusUtils.global.fire(ThemeChangeEvent.getInstance());
          update();
        });
        break;
      case 3:
        KqCoreGlobal.prefs!.setString('theme', Global.themeDark).then((value) {
          EventBusUtils.global.fire(ThemeChangeEvent.getInstance());
          update();
        });
        break;
    }
  }
}
